<HTML><HEAD><TITLE>sprintf(-String, +Format, ?ArgList)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Term I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>sprintf(-String, +Format, ?ArgList)</H1>
The arguments in the argument list ArgList are interpreted according to the
Format string and the formatted result is unified with String.
<DL>
<DT><EM>String</EM></DT>
<DD>Variable or String.
</DD>
<DT><EM>Format</EM></DT>
<DD>String or Atom.
</DD>
<DT><EM>ArgList</EM></DT>
<DD>List or any Term.
</DD>
</DL>
<H2>Description</H2>
    This predicate works exactly like printf/2,3 except that the formatted
    result is delivered in the form of a string.  See printf/2,3 for details.
<P>
    Note that for simple cases it is usually more efficient to use
    primitives like concat_string/2, join_string/3 or number_string/2.
<P>

<H3>Modes and Determinism</H3><UL>
<LI>sprintf(-, +, ?) is det
</UL>
<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H3>Exceptions</H3>
<DL>
<DT><EM>(5) type error </EM>
<DD>String is instantiated to something other than a string.
<DT><EM>(5) type error </EM>
<DD>Format is not an atom or a string.
<DT><EM>(5) type error </EM>
<DD>ArgList contains argument whose type does not correspond to the control sequence.
<DT><EM>(7) string contains unexpected characters </EM>
<DD>Format is not correct, it contains too many asterisks or a control character is missing or there is a redundant character before the control character.
<DT><EM>(8) bad argument list </EM>
<DD>ArgList has not enough or too many arguments.
</DL>
<H2>Examples</H2>
<PRE>
Success:
?- sprintf(String, "abc %s ghi %+*.*E...", ["def", 2, 3, 12.34]).
String = "abc def ghi +1.234E+01..."
yes.

?- sprintf(String, "abc %12c %*n", [77, 3]).
String = "abc MMMMMMMMMMMM \n\n\n"
yes.

?- sprintf("x9", "x%d", [3]).
no.
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/stratom/concat_string-2.html">concat_string / 2</A>, <A HREF="../../kernel/stratom/join_string-3.html">join_string / 3</A>, <A HREF="../../kernel/stratom/number_string-2.html">number_string / 2</A>, <A HREF="../../kernel/ioterm/printf-2.html">printf / 2</A>, <A HREF="../../kernel/ioterm/printf-3.html">printf / 3</A>
</BODY></HTML>
